package com.example.lxj.system.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.example.lxj.system.entity.SysUserToken;
import com.example.lxj.system.mapper.SysUserTokenMapper;
import com.example.lxj.system.service.ISysUserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户tokenService业务层处理
 */
@Service
public class SysUserTokenServiceImpl implements ISysUserTokenService
{
    @Autowired
    private SysUserTokenMapper sysUserTokenMapper;


    @Override
    public SysUserToken selectSysUserIdByUserToken(String userToken) {
        return sysUserTokenMapper.selectSysUserIdByUserToken(userToken);
    }

    /**
     * 新增或更新token
     * @param sysUserToken 用户token
     * @return
     */
    @Override
    public int insertOrUpdateSysUserToken(SysUserToken sysUserToken) {
        // 判断用户是存在 根据id
        SysUserToken userTokenExist = sysUserTokenMapper.selectSysUserTokenByUserId(sysUserToken.getUserId());
        if(ObjectUtil.isNull(userTokenExist)){
            return sysUserTokenMapper.insertSysUserToken(sysUserToken);
        }else{
            return sysUserTokenMapper.updateSysUserToken(sysUserToken);
        }
    }


}
